﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using HslCommunication.Core;
using HslCommunication.Core.Address;
using HslCommunication.Core.IMessage;
using HslCommunication.Core.Net;
using HslCommunication.Reflection;

namespace HslCommunication.Profinet.Melsec
{
	/// <summary>
	/// 三菱的R系列的MC协议，支持的地址类型和 <see cref="T:HslCommunication.Profinet.Melsec.MelsecMcNet" /> 有区别，详细请查看对应的API文档说明
	/// </summary>
	// Token: 0x02000071 RID: 113
	public class MelsecMcRNet : NetworkDeviceBase
	{
		/// <summary>
		/// 实例化三菱R系列的Qna兼容3E帧协议的通讯对象<br />
		/// Instantiate the communication object of Mitsubishi's Qna compatible 3E frame protocol
		/// </summary>
		// Token: 0x06000933 RID: 2355 RVA: 0x00034D32 File Offset: 0x00032F32
		public MelsecMcRNet()
		{
			base.WordLength = 1;
			base.ByteTransform = new RegularByteTransform();
		}

		/// <summary>
		/// 指定ip地址和端口号来实例化一个默认的对象<br />
		/// Specify the IP address and port number to instantiate a default object
		/// </summary>
		/// <param name="ipAddress">PLC的Ip地址</param>
		/// <param name="port">PLC的端口</param>
		// Token: 0x06000934 RID: 2356 RVA: 0x00034D5E File Offset: 0x00032F5E
		public MelsecMcRNet(string ipAddress, int port)
		{
			base.WordLength = 1;
			this.IpAddress = ipAddress;
			this.Port = port;
			base.ByteTransform = new RegularByteTransform();
		}

		/// <inheritdoc />
		// Token: 0x06000935 RID: 2357 RVA: 0x00034D9A File Offset: 0x00032F9A
		protected override INetMessage GetNewNetMessage()
		{
			return new MelsecQnA3EBinaryMessage();
		}

		/// <inheritdoc cref="P:HslCommunication.Profinet.Melsec.MelsecMcNet.NetworkNumber" />
		// Token: 0x17000193 RID: 403
		// (get) Token: 0x06000936 RID: 2358 RVA: 0x00034DA1 File Offset: 0x00032FA1
		// (set) Token: 0x06000937 RID: 2359 RVA: 0x00034DA9 File Offset: 0x00032FA9
		public byte NetworkNumber { get; set; } = 0;

		/// <inheritdoc cref="P:HslCommunication.Profinet.Melsec.MelsecMcNet.NetworkStationNumber" />
		// Token: 0x17000194 RID: 404
		// (get) Token: 0x06000938 RID: 2360 RVA: 0x00034DB2 File Offset: 0x00032FB2
		// (set) Token: 0x06000939 RID: 2361 RVA: 0x00034DBA File Offset: 0x00032FBA
		public byte NetworkStationNumber { get; set; } = 0;

		/// <inheritdoc />
		// Token: 0x0600093A RID: 2362 RVA: 0x00034DC4 File Offset: 0x00032FC4
		[HslMqttApi("ReadByteArray", "")]
		public override OperateResult<byte[]> Read(string address, ushort length)
		{
			OperateResult<McRAddressData> operateResult = McRAddressData.ParseMelsecRFrom(address, length);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				List<byte> list = new List<byte>();
				ushort num = 0;
				while (num < length)
				{
					ushort num2 = (ushort)Math.Min((int)(length - num), 900);
					operateResult.Content.Length = num2;
					OperateResult<byte[]> operateResult2 = this.ReadAddressData(operateResult.Content, false);
					bool flag2 = !operateResult2.IsSuccess;
					if (flag2)
					{
						return operateResult2;
					}
					list.AddRange(operateResult2.Content);
					num += num2;
					bool flag3 = operateResult.Content.McDataType.DataType == 0;
					if (flag3)
					{
						operateResult.Content.AddressStart += (int)num2;
					}
					else
					{
						operateResult.Content.AddressStart += (int)(num2 * 16);
					}
				}
				result = OperateResult.CreateSuccessResult<byte[]>(list.ToArray());
			}
			return result;
		}

		// Token: 0x0600093B RID: 2363 RVA: 0x00034EC0 File Offset: 0x000330C0
		private OperateResult<byte[]> ReadAddressData(McRAddressData address, bool isBit)
		{
			byte[] mcCore = MelsecMcRNet.BuildReadMcCoreCommand(address, isBit);
			OperateResult<byte[]> operateResult = base.ReadFromCoreServer(MelsecMcNet.PackMcCommand(mcCore, this.NetworkNumber, this.NetworkStationNumber));
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				OperateResult operateResult2 = MelsecMcNet.CheckResponseContent(operateResult.Content);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<byte[]>(operateResult2);
				}
				else
				{
					result = MelsecMcNet.ExtractActualData(operateResult.Content.RemoveBegin(11), isBit);
				}
			}
			return result;
		}

		/// <inheritdoc />
		// Token: 0x0600093C RID: 2364 RVA: 0x00034F44 File Offset: 0x00033144
		[HslMqttApi("WriteByteArray", "")]
		public override OperateResult Write(string address, byte[] value)
		{
			OperateResult<McRAddressData> operateResult = McRAddressData.ParseMelsecRFrom(address, 0);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				result = this.WriteAddressData(operateResult.Content, value);
			}
			return result;
		}

		// Token: 0x0600093D RID: 2365 RVA: 0x00034F84 File Offset: 0x00033184
		private OperateResult WriteAddressData(McRAddressData addressData, byte[] value)
		{
			byte[] mcCore = MelsecMcRNet.BuildWriteWordCoreCommand(addressData, value);
			OperateResult<byte[]> operateResult = base.ReadFromCoreServer(MelsecMcNet.PackMcCommand(mcCore, this.NetworkNumber, this.NetworkStationNumber));
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				OperateResult operateResult2 = MelsecMcNet.CheckResponseContent(operateResult.Content);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<byte[]>(operateResult2);
				}
				else
				{
					result = OperateResult.CreateSuccessResult();
				}
			}
			return result;
		}

		/// <inheritdoc />
		// Token: 0x0600093E RID: 2366 RVA: 0x00034FF8 File Offset: 0x000331F8
		[DebuggerStepThrough]
		public override Task<OperateResult<byte[]>> ReadAsync(string address, ushort length)
		{
			MelsecMcRNet.<ReadAsync>d__15 <ReadAsync>d__ = new MelsecMcRNet.<ReadAsync>d__15();
			<ReadAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
			<ReadAsync>d__.<>4__this = this;
			<ReadAsync>d__.address = address;
			<ReadAsync>d__.length = length;
			<ReadAsync>d__.<>1__state = -1;
			<ReadAsync>d__.<>t__builder.Start<MelsecMcRNet.<ReadAsync>d__15>(ref <ReadAsync>d__);
			return <ReadAsync>d__.<>t__builder.Task;
		}

		// Token: 0x0600093F RID: 2367 RVA: 0x0003504C File Offset: 0x0003324C
		[DebuggerStepThrough]
		private Task<OperateResult<byte[]>> ReadAddressDataAsync(McRAddressData address, bool isBit)
		{
			MelsecMcRNet.<ReadAddressDataAsync>d__16 <ReadAddressDataAsync>d__ = new MelsecMcRNet.<ReadAddressDataAsync>d__16();
			<ReadAddressDataAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
			<ReadAddressDataAsync>d__.<>4__this = this;
			<ReadAddressDataAsync>d__.address = address;
			<ReadAddressDataAsync>d__.isBit = isBit;
			<ReadAddressDataAsync>d__.<>1__state = -1;
			<ReadAddressDataAsync>d__.<>t__builder.Start<MelsecMcRNet.<ReadAddressDataAsync>d__16>(ref <ReadAddressDataAsync>d__);
			return <ReadAddressDataAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc />
		// Token: 0x06000940 RID: 2368 RVA: 0x000350A0 File Offset: 0x000332A0
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, byte[] value)
		{
			MelsecMcRNet.<WriteAsync>d__17 <WriteAsync>d__ = new MelsecMcRNet.<WriteAsync>d__17();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<MelsecMcRNet.<WriteAsync>d__17>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		// Token: 0x06000941 RID: 2369 RVA: 0x000350F4 File Offset: 0x000332F4
		[DebuggerStepThrough]
		private Task<OperateResult> WriteAddressDataAsync(McRAddressData addressData, byte[] value)
		{
			MelsecMcRNet.<WriteAddressDataAsync>d__18 <WriteAddressDataAsync>d__ = new MelsecMcRNet.<WriteAddressDataAsync>d__18();
			<WriteAddressDataAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAddressDataAsync>d__.<>4__this = this;
			<WriteAddressDataAsync>d__.addressData = addressData;
			<WriteAddressDataAsync>d__.value = value;
			<WriteAddressDataAsync>d__.<>1__state = -1;
			<WriteAddressDataAsync>d__.<>t__builder.Start<MelsecMcRNet.<WriteAddressDataAsync>d__18>(ref <WriteAddressDataAsync>d__);
			return <WriteAddressDataAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc />
		// Token: 0x06000942 RID: 2370 RVA: 0x00035148 File Offset: 0x00033348
		[HslMqttApi("ReadBoolArray", "")]
		public override OperateResult<bool[]> ReadBool(string address, ushort length)
		{
			OperateResult<McRAddressData> operateResult = McRAddressData.ParseMelsecRFrom(address, length);
			bool flag = !operateResult.IsSuccess;
			OperateResult<bool[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				byte[] mcCore = MelsecMcRNet.BuildReadMcCoreCommand(operateResult.Content, true);
				OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(MelsecMcNet.PackMcCommand(mcCore, this.NetworkNumber, this.NetworkStationNumber));
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<bool[]>(operateResult2);
				}
				else
				{
					OperateResult operateResult3 = MelsecMcNet.CheckResponseContent(operateResult2.Content);
					bool flag3 = !operateResult3.IsSuccess;
					if (flag3)
					{
						result = OperateResult.CreateFailedResult<bool[]>(operateResult3);
					}
					else
					{
						OperateResult<byte[]> operateResult4 = MelsecMcNet.ExtractActualData(operateResult2.Content.RemoveBegin(11), true);
						bool flag4 = !operateResult4.IsSuccess;
						if (flag4)
						{
							result = OperateResult.CreateFailedResult<bool[]>(operateResult4);
						}
						else
						{
							result = OperateResult.CreateSuccessResult<bool[]>(Enumerable.ToArray<bool>(Enumerable.Take<bool>(Enumerable.Select<byte, bool>(operateResult4.Content, (byte m) => m == 1), (int)length)));
						}
					}
				}
			}
			return result;
		}

		/// <inheritdoc />
		// Token: 0x06000943 RID: 2371 RVA: 0x00035254 File Offset: 0x00033454
		[HslMqttApi("WriteBoolArray", "")]
		public override OperateResult Write(string address, bool[] values)
		{
			OperateResult<McRAddressData> operateResult = McRAddressData.ParseMelsecRFrom(address, 0);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				byte[] mcCore = MelsecMcRNet.BuildWriteBitCoreCommand(operateResult.Content, values);
				OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(MelsecMcNet.PackMcCommand(mcCore, this.NetworkNumber, this.NetworkStationNumber));
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					OperateResult operateResult3 = MelsecMcNet.CheckResponseContent(operateResult2.Content);
					bool flag3 = !operateResult3.IsSuccess;
					if (flag3)
					{
						result = operateResult3;
					}
					else
					{
						result = OperateResult.CreateSuccessResult();
					}
				}
			}
			return result;
		}

		/// <inheritdoc />
		// Token: 0x06000944 RID: 2372 RVA: 0x000352E4 File Offset: 0x000334E4
		[DebuggerStepThrough]
		public override Task<OperateResult<bool[]>> ReadBoolAsync(string address, ushort length)
		{
			MelsecMcRNet.<ReadBoolAsync>d__21 <ReadBoolAsync>d__ = new MelsecMcRNet.<ReadBoolAsync>d__21();
			<ReadBoolAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<bool[]>>.Create();
			<ReadBoolAsync>d__.<>4__this = this;
			<ReadBoolAsync>d__.address = address;
			<ReadBoolAsync>d__.length = length;
			<ReadBoolAsync>d__.<>1__state = -1;
			<ReadBoolAsync>d__.<>t__builder.Start<MelsecMcRNet.<ReadBoolAsync>d__21>(ref <ReadBoolAsync>d__);
			return <ReadBoolAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc />
		// Token: 0x06000945 RID: 2373 RVA: 0x00035338 File Offset: 0x00033538
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, bool[] values)
		{
			MelsecMcRNet.<WriteAsync>d__22 <WriteAsync>d__ = new MelsecMcRNet.<WriteAsync>d__22();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.values = values;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<MelsecMcRNet.<WriteAsync>d__22>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <summary>
		/// 分析三菱R系列的地址，并返回解析后的数据对象
		/// </summary>
		/// <param name="address">字符串地址</param>
		/// <returns>是否解析成功</returns>
		// Token: 0x06000946 RID: 2374 RVA: 0x0003538C File Offset: 0x0003358C
		public static OperateResult<MelsecMcRDataType, int> AnalysisAddress(string address)
		{
			OperateResult<MelsecMcRDataType, int> result;
			try
			{
				bool flag = address.StartsWith("LSTS");
				if (flag)
				{
					result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.LSTS, Convert.ToInt32(address.Substring(4), MelsecMcRDataType.LSTS.FromBase));
				}
				else
				{
					bool flag2 = address.StartsWith("LSTC");
					if (flag2)
					{
						result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.LSTC, Convert.ToInt32(address.Substring(4), MelsecMcRDataType.LSTC.FromBase));
					}
					else
					{
						bool flag3 = address.StartsWith("LSTN");
						if (flag3)
						{
							result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.LSTN, Convert.ToInt32(address.Substring(4), MelsecMcRDataType.LSTN.FromBase));
						}
						else
						{
							bool flag4 = address.StartsWith("STS");
							if (flag4)
							{
								result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.STS, Convert.ToInt32(address.Substring(3), MelsecMcRDataType.STS.FromBase));
							}
							else
							{
								bool flag5 = address.StartsWith("STC");
								if (flag5)
								{
									result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.STC, Convert.ToInt32(address.Substring(3), MelsecMcRDataType.STC.FromBase));
								}
								else
								{
									bool flag6 = address.StartsWith("STN");
									if (flag6)
									{
										result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.STN, Convert.ToInt32(address.Substring(3), MelsecMcRDataType.STN.FromBase));
									}
									else
									{
										bool flag7 = address.StartsWith("LTS");
										if (flag7)
										{
											result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.LTS, Convert.ToInt32(address.Substring(3), MelsecMcRDataType.LTS.FromBase));
										}
										else
										{
											bool flag8 = address.StartsWith("LTC");
											if (flag8)
											{
												result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.LTC, Convert.ToInt32(address.Substring(3), MelsecMcRDataType.LTC.FromBase));
											}
											else
											{
												bool flag9 = address.StartsWith("LTN");
												if (flag9)
												{
													result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.LTN, Convert.ToInt32(address.Substring(3), MelsecMcRDataType.LTN.FromBase));
												}
												else
												{
													bool flag10 = address.StartsWith("LCS");
													if (flag10)
													{
														result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.LCS, Convert.ToInt32(address.Substring(3), MelsecMcRDataType.LCS.FromBase));
													}
													else
													{
														bool flag11 = address.StartsWith("LCC");
														if (flag11)
														{
															result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.LCC, Convert.ToInt32(address.Substring(3), MelsecMcRDataType.LCC.FromBase));
														}
														else
														{
															bool flag12 = address.StartsWith("LCN");
															if (flag12)
															{
																result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.LCN, Convert.ToInt32(address.Substring(3), MelsecMcRDataType.LCN.FromBase));
															}
															else
															{
																bool flag13 = address.StartsWith("TS");
																if (flag13)
																{
																	result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.TS, Convert.ToInt32(address.Substring(2), MelsecMcRDataType.TS.FromBase));
																}
																else
																{
																	bool flag14 = address.StartsWith("TC");
																	if (flag14)
																	{
																		result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.TC, Convert.ToInt32(address.Substring(2), MelsecMcRDataType.TC.FromBase));
																	}
																	else
																	{
																		bool flag15 = address.StartsWith("TN");
																		if (flag15)
																		{
																			result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.TN, Convert.ToInt32(address.Substring(2), MelsecMcRDataType.TN.FromBase));
																		}
																		else
																		{
																			bool flag16 = address.StartsWith("CS");
																			if (flag16)
																			{
																				result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.CS, Convert.ToInt32(address.Substring(2), MelsecMcRDataType.CS.FromBase));
																			}
																			else
																			{
																				bool flag17 = address.StartsWith("CC");
																				if (flag17)
																				{
																					result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.CC, Convert.ToInt32(address.Substring(2), MelsecMcRDataType.CC.FromBase));
																				}
																				else
																				{
																					bool flag18 = address.StartsWith("CN");
																					if (flag18)
																					{
																						result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.CN, Convert.ToInt32(address.Substring(2), MelsecMcRDataType.CN.FromBase));
																					}
																					else
																					{
																						bool flag19 = address.StartsWith("SM");
																						if (flag19)
																						{
																							result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.SM, Convert.ToInt32(address.Substring(2), MelsecMcRDataType.SM.FromBase));
																						}
																						else
																						{
																							bool flag20 = address.StartsWith("SB");
																							if (flag20)
																							{
																								result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.SB, Convert.ToInt32(address.Substring(2), MelsecMcRDataType.SB.FromBase));
																							}
																							else
																							{
																								bool flag21 = address.StartsWith("DX");
																								if (flag21)
																								{
																									result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.DX, Convert.ToInt32(address.Substring(2), MelsecMcRDataType.DX.FromBase));
																								}
																								else
																								{
																									bool flag22 = address.StartsWith("DY");
																									if (flag22)
																									{
																										result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.DY, Convert.ToInt32(address.Substring(2), MelsecMcRDataType.DY.FromBase));
																									}
																									else
																									{
																										bool flag23 = address.StartsWith("SD");
																										if (flag23)
																										{
																											result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.SD, Convert.ToInt32(address.Substring(2), MelsecMcRDataType.SD.FromBase));
																										}
																										else
																										{
																											bool flag24 = address.StartsWith("SW");
																											if (flag24)
																											{
																												result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.SW, Convert.ToInt32(address.Substring(2), MelsecMcRDataType.SW.FromBase));
																											}
																											else
																											{
																												bool flag25 = address.StartsWith("X");
																												if (flag25)
																												{
																													result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.X, Convert.ToInt32(address.Substring(1), MelsecMcRDataType.X.FromBase));
																												}
																												else
																												{
																													bool flag26 = address.StartsWith("Y");
																													if (flag26)
																													{
																														result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.Y, Convert.ToInt32(address.Substring(1), MelsecMcRDataType.Y.FromBase));
																													}
																													else
																													{
																														bool flag27 = address.StartsWith("M");
																														if (flag27)
																														{
																															result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.M, Convert.ToInt32(address.Substring(1), MelsecMcRDataType.M.FromBase));
																														}
																														else
																														{
																															bool flag28 = address.StartsWith("L");
																															if (flag28)
																															{
																																result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.L, Convert.ToInt32(address.Substring(1), MelsecMcRDataType.L.FromBase));
																															}
																															else
																															{
																																bool flag29 = address.StartsWith("F");
																																if (flag29)
																																{
																																	result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.F, Convert.ToInt32(address.Substring(1), MelsecMcRDataType.F.FromBase));
																																}
																																else
																																{
																																	bool flag30 = address.StartsWith("V");
																																	if (flag30)
																																	{
																																		result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.V, Convert.ToInt32(address.Substring(1), MelsecMcRDataType.V.FromBase));
																																	}
																																	else
																																	{
																																		bool flag31 = address.StartsWith("S");
																																		if (flag31)
																																		{
																																			result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.S, Convert.ToInt32(address.Substring(1), MelsecMcRDataType.S.FromBase));
																																		}
																																		else
																																		{
																																			bool flag32 = address.StartsWith("B");
																																			if (flag32)
																																			{
																																				result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.B, Convert.ToInt32(address.Substring(1), MelsecMcRDataType.B.FromBase));
																																			}
																																			else
																																			{
																																				bool flag33 = address.StartsWith("D");
																																				if (flag33)
																																				{
																																					result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.D, Convert.ToInt32(address.Substring(1), MelsecMcRDataType.D.FromBase));
																																				}
																																				else
																																				{
																																					bool flag34 = address.StartsWith("W");
																																					if (flag34)
																																					{
																																						result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.W, Convert.ToInt32(address.Substring(1), MelsecMcRDataType.W.FromBase));
																																					}
																																					else
																																					{
																																						bool flag35 = address.StartsWith("R");
																																						if (flag35)
																																						{
																																							result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.R, Convert.ToInt32(address.Substring(1), MelsecMcRDataType.R.FromBase));
																																						}
																																						else
																																						{
																																							bool flag36 = address.StartsWith("Z");
																																							if (flag36)
																																							{
																																								result = OperateResult.CreateSuccessResult<MelsecMcRDataType, int>(MelsecMcRDataType.Z, Convert.ToInt32(address.Substring(1), MelsecMcRDataType.Z.FromBase));
																																							}
																																							else
																																							{
																																								result = new OperateResult<MelsecMcRDataType, int>(StringResources.Language.NotSupportedDataType);
																																							}
																																						}
																																					}
																																				}
																																			}
																																		}
																																	}
																																}
																															}
																														}
																													}
																												}
																											}
																										}
																									}
																								}
																							}
																						}
																					}
																				}
																			}
																		}
																	}
																}
															}
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
			catch (Exception ex)
			{
				result = new OperateResult<MelsecMcRDataType, int>(ex.Message);
			}
			return result;
		}

		/// <summary>
		/// 从三菱地址，是否位读取进行创建读取的MC的核心报文
		/// </summary>
		/// <param name="address">地址数据</param>
		/// <param name="isBit">是否进行了位读取操作</param>
		/// <returns>带有成功标识的报文对象</returns>
		// Token: 0x06000947 RID: 2375 RVA: 0x00035B8C File Offset: 0x00033D8C
		public static byte[] BuildReadMcCoreCommand(McRAddressData address, bool isBit)
		{
			return new byte[]
			{
				1,
				4,
				isBit ? 1 : 0,
				0,
				BitConverter.GetBytes(address.AddressStart)[0],
				BitConverter.GetBytes(address.AddressStart)[1],
				BitConverter.GetBytes(address.AddressStart)[2],
				BitConverter.GetBytes(address.AddressStart)[3],
				address.McDataType.DataCode[0],
				address.McDataType.DataCode[1],
				(byte)(address.Length % 256),
				(byte)(address.Length / 256)
			};
		}

		/// <summary>
		/// 以字为单位，创建数据写入的核心报文
		/// </summary>
		/// <param name="address">三菱的数据地址</param>
		/// <param name="value">实际的原始数据信息</param>
		/// <returns>带有成功标识的报文对象</returns>
		// Token: 0x06000948 RID: 2376 RVA: 0x00035C40 File Offset: 0x00033E40
		public static byte[] BuildWriteWordCoreCommand(McRAddressData address, byte[] value)
		{
			bool flag = value == null;
			if (flag)
			{
				value = new byte[0];
			}
			byte[] array = new byte[12 + value.Length];
			array[0] = 1;
			array[1] = 20;
			array[2] = 0;
			array[3] = 0;
			array[4] = BitConverter.GetBytes(address.AddressStart)[0];
			array[5] = BitConverter.GetBytes(address.AddressStart)[1];
			array[6] = BitConverter.GetBytes(address.AddressStart)[2];
			array[7] = BitConverter.GetBytes(address.AddressStart)[3];
			array[8] = address.McDataType.DataCode[0];
			array[9] = address.McDataType.DataCode[1];
			array[10] = (byte)(value.Length / 2 % 256);
			array[11] = (byte)(value.Length / 2 / 256);
			value.CopyTo(array, 12);
			return array;
		}

		/// <summary>
		/// 以位为单位，创建数据写入的核心报文
		/// </summary>
		/// <param name="address">三菱的地址信息</param>
		/// <param name="value">原始的bool数组数据</param>
		/// <returns>带有成功标识的报文对象</returns>
		// Token: 0x06000949 RID: 2377 RVA: 0x00035D0C File Offset: 0x00033F0C
		public static byte[] BuildWriteBitCoreCommand(McRAddressData address, bool[] value)
		{
			bool flag = value == null;
			if (flag)
			{
				value = new bool[0];
			}
			byte[] array = MelsecHelper.TransBoolArrayToByteData(value);
			byte[] array2 = new byte[12 + array.Length];
			array2[0] = 1;
			array2[1] = 20;
			array2[2] = 1;
			array2[3] = 0;
			array2[4] = BitConverter.GetBytes(address.AddressStart)[0];
			array2[5] = BitConverter.GetBytes(address.AddressStart)[1];
			array2[6] = BitConverter.GetBytes(address.AddressStart)[2];
			array2[7] = BitConverter.GetBytes(address.AddressStart)[3];
			array2[8] = address.McDataType.DataCode[0];
			array2[9] = address.McDataType.DataCode[1];
			array2[10] = (byte)(value.Length % 256);
			array2[11] = (byte)(value.Length / 256);
			array.CopyTo(array2, 12);
			return array2;
		}
	}
}
